package com.gitee.feizns.test;

import com.gitee.feizns.quickstart.mybatis.flex.query.Query;
import com.gitee.feizns.quickstart.mybatis.flex.validation.constraints.Exist;
import com.gitee.feizns.quickstart.web.domain.query.QueryBodyAo;
import com.gitee.feizns.quickstart.web.domain.query.QueryParamsAo;
import com.gitee.feizns.test.domain.pojo.Hello;
import com.mybatisflex.core.query.QueryChain;
import lombok.Data;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Hello world!
 */
//@MapperScan("com.gitee.feizns.test.mapper")
@EntityScan
@RestController
@SpringBootApplication
public class App {

    public static void main(String[] args) {
        SpringApplication.run(App.class, args);

//        WebUtils.getReq()
//        System.out.println(dict);
//        A a = new A();
//        a.setId(2L);
//        System.out.println();
//        List<Entry> list = Dict.list();
//        System.out.println(dict);
//        for (Entry entry : list) {
////            System.out.println(dict);
////            if ( dict == null )
////                dict = new QkDict();
////            dict.of(entry);
////            dict.saveOrUpdate();
//        }
//        for (Entry entry : entries) {

//        }
//        Entry entry = Dict.put("hello", "");
//        System.out.println(entry);
//        System.out.println(entry);
//        System.out.println(Dict.get("hello"));
//        ValidationUtils.validateIfFailsThenThrow(a);
    }

    /**
     * 日志
     * @param ao 请求参数
     * @return {@link List}<{@link Hello}>
     */
    @GetMapping("/test")
    public List<Hello> log(QueryParamsAo ao) {
        return QueryChain.of(Hello.class).baseMapper().selectListByQuery(Query.of(ao));
    }

    /**
     * 日志
     * @param ao 请求参数
     * @return {@link List}<{@link Hello}>
     */
    @PostMapping("/test1")
    public List<Hello> log(@RequestBody QueryBodyAo ao) {
        return QueryChain.of(Hello.class).baseMapper().selectListByQuery(Query.of(ao));
    }

    @Data
    public static class A {

        @Exist(field = "id", type = Hello.class)
        private Long id;

    }

}
